package com.selenium.zuoye;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

class importXLS {
	String filePath;

	public importXLS(String filePath) {
		super();
		this.filePath = filePath;
	}

	public List<String[]> importXLS1() {
		ArrayList<String[]> list = new ArrayList<String[]>();
		try {
			//1、获取文件输入流
			InputStream inputStream = new FileInputStream(filePath);
			//2、获取Excel工作簿对象
			XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
			//3、得到Excel工作表对象
			XSSFSheet sheetAt = workbook.getSheetAt(0);
			System.out.println();
			int num = sheetAt.getLastRowNum();
			// 4、循环读取表格数据
			for (int i = 0; i <= num; i++) {
				Row row = sheetAt.getRow(i);
				if (row != null) {
					// 首行（即表头）不读取
					if (row.getRowNum() == 0) {
						continue;
					}
					// 读取当前行中单元格数据，索引从0开始
					String method = null;
					org.apache.poi.ss.usermodel.Cell cell = row.getCell(0);
					if (cell != null) {
						method = cell.getStringCellValue();
					}
					String data = null;
					cell = row.getCell(1);
					if (cell != null) {
						data = cell.getStringCellValue();
					}
					String expeted = null;
					cell = row.getCell(2);
					if (cell != null) {
						expeted = cell.getStringCellValue();
					}
					String obj[] = new String[] { method, data, expeted };
					list.add(obj);
				} else {
					break;
				}
			}
			// 5、关闭流
			workbook.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
		}
		return list;
	}
}